<style>
.app-main{
  background: #f5f9ff;
}
.container {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
  width: 1300px;
  margin: auto;
}
.card {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  padding: 20px;
  width: 300px;
}
.card h2 {
  margin: 0;
  font-size: 36px;
}
.card p {
  margin: 8px 0;
  color: #888;
}
.task-list {
  background-color: #fff;
  border-radius: 8px;
  padding: 20px;
  width: 1300px;
  margin: 20px auto;
}
.task-item {
  display: inline-block;
  width: 175px;
  text-align: center;
}
.task-item .db {
  margin: 10px 0 0;
  font-size: 20px;
  color: #006eff;
  font-weight: bold;
}
</style>

<template>
  <div class="app-container">
    <div class="container">
      <div class="card">
        <p>待调度订单</p>
        <h2>{{this.waitDispatch}}</h2>
        <p>较上月 ▲ 12%</p>
      </div>
      <div class="card">
        <p>待接单运单</p>
        <h2>{{this.waitReceive}}</h2>
        <p>较上月 ▲ 12%</p>
      </div>
      <div class="card">
        <p>运输中的运单</p>
        <h2>{{this.onTheWay}}</h2>
        <p>较上月 ▲ 1%</p>
      </div>
      <div class="card">
        <p>异常运单</p>
        <h2>{{this.exception}}</h2>
        <p>较上月 ▲ 20%</p>
      </div>
    </div>

    <div class="task-list">
      <h3>待办事项</h3>
      <div class="task-item">
        <h5>待调度订单</h5>
        <p><el-link class="db" @click="handleOpen('待调度')" type="primary">{{this.waitDispatch}}</el-link></p>
      </div>
      <div class="task-item">
        <h5>待审核订单</h5>
        <p><el-link class="db" @click="handleOpen('待审核')" type="primary">{{this.waitAudit}}</el-link></p>
      </div>
      <div class="task-item">
        <h5>待发车运单</h5>
        <p><el-link class="db" @click="yunDan('待发车')" type="primary">{{this.waitSend}}</el-link></p>
      </div>
      <div class="task-item">
        <h5>在途运单</h5>
        <p><el-link class="db" @click="yunDan('运输中')"  type="primary">{{this.onTheWay}}</el-link></p>
      </div>
      <div class="task-item">
        <h5>待签收订单</h5>
        <p><el-link class="db" @click="handleOpen('待签收')" type="primary">{{this.waitSign}}</el-link></p>
      </div>
      <div class="task-item">
        <h5>待处理异常事件</h5>
        <p><el-link class="db" @click="handException('待处理')" type="primary">{{this.waitDealException}}</el-link></p>
      </div>
      <div class="task-item">
        <h5>待确认回单</h5>
        <p><el-link class="db" @click="huiDan('未回收')" type="primary">{{this.waitConfirm}}</el-link></p>
      </div>
    </div>

    <div style="margin: 20px auto; padding: 20px; border-radius:5px; width: 1300px; background: #FFFFFF">
      <div id="map" style="width: 1300px; height: 400px;"></div>
    </div>

    <div class="shishi" style="margin: auto; padding: 20px; border-radius:5px; width: 1300px; background: #FFFFFF">
      <h3>实时订单</h3>
      <el-table v-loading="loading" :data="goodsList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <!--      <el-table-column label="编号" align="center" prop="id" />-->
        <el-table-column label="订单号" align="center" prop="ddh" />
        <el-table-column label="始发地" align="center" prop="sfd" />
        <el-table-column label="目的地" align="center" prop="mdd" />
        <el-table-column label="客户名称" align="center" prop="kcname" />
        <el-table-column label="订单状态" align="center" prop="status">
<!--          <template slot-scope="scope">-->
<!--            <el-tag v-if="scope.row.status==0" type="info">待调度</el-tag>-->
<!--            <el-tag v-else-if="scope.row.status==1" type="success">已调度</el-tag>-->
<!--          </template>-->
        </el-table-column>
        <el-table-column label="货物数量" align="center" prop="hwnum" />
        <el-table-column label="总体积" align="center" prop="ztj">
          <template slot-scope="scope">
            <span>{{ scope.row.ztj }}m³</span>
          </template>
        </el-table-column>
        <el-table-column label="总重量" align="center" prop="zl">
          <template slot-scope="scope">
            <span>{{ scope.row.zl }}kg</span>
          </template>
        </el-table-column>
        <el-table-column label="运费合计" align="center" prop="yfhj" />
        <el-table-column label="下单时间" align="center" prop="time" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.time, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>

  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder } from "@/api/order/order/order";
import {parseTime} from "../utils/ruoyi";
import {countGoods, listGoods, todoGoods} from "@/api/goods/goods";
import * as echarts from 'echarts';

const option = {
  title: {
    text: '本月订单趋势'
  },
  tooltip: {
    trigger: 'axis'
  },
  xAxis: {
    type: 'category',
    data: []
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      data: [],
      type: 'line',
      smooth: true
    }
  ]
};

export default {
  name: "Order",
  data() {
    return {
      //待调度订单
      waitDispatch: 0,
      //待审核订单
      waitAudit: 0,
      //待发车订单
      waitSend: 0,
      //在途订单
      onTheWay: 0,
      //待签收订单
      waitSign: 0,
      //待处理异常订单
      waitDealException: 0,
      //待确认回单
      waitConfirm: 0,
      //待接单运单
      waitReceive: 0,
      //异常运单
      exception: 0,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单统计表格数据
      orderList: [],
      goodsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 下单时间时间范围
      daterangeTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        time: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    //待办事项
    this.getOrders();
  },
  mounted() {
    let chartDom = document.getElementById('map');
    let myChart = echarts.init(chartDom);
    myChart.setOption(option);

    countGoods().then(res => {
      let data = res.rows;
      let xData = [];
      let yData = [];
      for (let i = 0; i < data.length; i++) {
        xData.push(data[i].time);
        yData.push(data[i].num);
      }
      option.xAxis.data = xData;
      option.series[0].data = yData;
      myChart.setOption(option);
    });
  },
  methods: {
    huiDan(returnStatus){
      this.$router.push({path: '/operation/silp', query:{returnStatus:returnStatus}});
    },
    handException(processingStatus){
      this.$router.push({path: '/monitoring/exmanagement', query:{processingStatus:processingStatus}});
    },
    yunDan(waybillStatus){
      this.$router.push({path: '/operation/operation', query:{waybillStatus:waybillStatus}});
    },
    handleOpen(status){
      this.$router.push({path: '/goods/goods',query:{status:status}});
    },
    getOrders(){
      this.loading = true;
      todoGoods().then(res => {
        this.waitDispatch = res.rows[0].ddd;
        this.waitAudit = res.rows[0].dsh;
        this.waitSend = res.rows[0].dfc;
        this.onTheWay = res.rows[0].ysz;
        this.waitSign = res.rows[0].dqs;
        this.waitDealException = res.rows[0].dcl;
        this.waitConfirm = res.rows[0].dhs;
        this.waitReceive = res.rows[0].djd;
        this.exception = res.rows[0].ycyd;
        this.loading = false;
      })
    },
    parseTime,
    /** 查询订单统计列表 */
    getList() {
      // this.loading = true;
      // this.queryParams.params = {};
      // if (null != this.daterangeTime && '' != this.daterangeTime) {
      //   this.queryParams.params["beginTime"] = this.daterangeTime[0];
      //   this.queryParams.params["endTime"] = this.daterangeTime[1];
      // }
      // listOrder(this.queryParams).then(response => {
      //   this.orderList = response.rows;
      //   this.total = response.total;
      //   this.loading = false;
      // });
      this.loading = true;
      listGoods(this.queryParams).then(response => {
          this.goodsList = response.rows;
          this.total = response.total;
          this.loading = false;
      })
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        ddh: null,
        startaddr: null,
        endaddr: null,
        name: null,
        status: null,
        num: null,
        tj: null,
        zl: null,
        hj: null,
        time: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单统计";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单统计";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除订单统计编号为"' + ids + '"的数据项？').then(function() {
        return delOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('order/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>



